package hr_project.hr.biz.Emp;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import hr_project.hr.dao.emp.IEmpDao;
import hr_project.hr.entity.Archives;
import hr_project.hr.entity.Emp;
import hr_project.hr.util.ExcelBean;
import hr_project.hr.util.ExcelUtil;
import hr_project.hr.util.QueryEmp;
import hr_project.hr.util.pagebean;

@Service("empbiz")
public class EmpBizImpl implements IEmpBiz {

	@Autowired
	private IEmpDao dao;
	public IEmpDao getDao() {
		return dao;
	}
	public void setDao(IEmpDao dao) {
		this.dao = dao;
	}
	@Override
	public Emp getLog(String name, String pwd) {
		// TODO Auto-generated method stub
		return dao.getLog(name, pwd);
	}

	@Override
	public void modEmp(Emp e) {
		// TODO Auto-generated method stub
		dao.modEmp(e);
	}

	@Override
	public Emp getById(long id) {
		// TODO Auto-generated method stub
		return dao.getById(id);
	}
	@Override
	public pagebean getAll(QueryEmp query, int page) {
		// TODO Auto-generated method stub
		
		pagebean pb=new pagebean();
		
		pb.setCurrpage(page);
		pb.setList(dao.getByPage(query, page, pb.getPageSize()));
		pb.setTotalRow(dao.getRowCount(query));
		
		return pb;
	}
	@Override
	public void addEmp(Emp e) {
		// TODO Auto-generated method stub
		dao.addEmp(e);
	}
	@Override
	public pagebean getDel(QueryEmp query, int page) {
		// TODO Auto-generated method stub
		
		pagebean pb=new pagebean();
		
		pb.setCurrpage(page);
		pb.setList(dao.getByPage2(query, page, pb.getPageSize()));
		pb.setTotalRow(dao.getRowCount2(query));
		
		return pb;
	}
	@Override
	public List<Emp> getOther(long depid) {
		// TODO Auto-generated method stub
		return dao.getOther(depid);
	}
	@Override
	public Emp getManageById(long dep_id) {
		// TODO Auto-generated method stub
		return dao.getManageById(dep_id);
	}
	@Override
	public List<Map<String, Object>> getCount() {
		// TODO Auto-generated method stub
		return dao.getCount();
	}
	@Override
	public List<Map<String, Object>> getCountsum() {
		// TODO Auto-generated method stub
		return dao.getCountsum();
	}
	@Override
	public XSSFWorkbook emexcel() {
		// TODO Auto-generated method stub
		  //在dao层中获取数据
				List<Map<String,Object>> list = dao.findAll();
				 //设置一个集合用来存放每一行的数据也就是一个ExcelBean对象
				 List<ExcelBean> excel = new ArrayList<>();
				 //行号，对应一个对象
				 Map<Integer,List<ExcelBean>> map = new LinkedHashMap<>();
				//设置标题栏
				 excel.add(new ExcelBean("员工编号","eid",0));
				 excel.add(new ExcelBean("员工姓名","ename",0));
				 excel.add(new ExcelBean("性别","sex",0));
				 excel.add(new ExcelBean("电话","phone", 0));
				 excel.add(new ExcelBean("邮箱","email",0));
				 excel.add(new ExcelBean("地址","address", 0));
				 excel.add(new ExcelBean("出生日期","birth",0));
				 excel.add(new ExcelBean("部门名称","dname",0));
				 excel.add(new ExcelBean("部门编号","did",0));
				 map.put(0,excel);
				 String sheetName = "员工信息表";
				 
				//调用ExcelUtil方法
				 XSSFWorkbook xssfWorkbook=null;
				 
				 try {
					 
					xssfWorkbook = ExcelUtil.createExcelFile(Emp.class, list, map, sheetName);
				    
				 
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IntrospectionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				 
				 return xssfWorkbook;
	}
	@Override
	public Emp getByQuery(String key) {
		// TODO Auto-generated method stub
		return dao.getByQuery(key);
	}
	@Override
	public List<Emp> getAllxx() {
		// TODO Auto-generated method stub
		return dao.getAll();
	}

}
